package cn.tedu.sp04.controller;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.sp01.util.JsonResult;
import com.sun.org.apache.xpath.internal.operations.Or;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId){
        return JsonResult.ok().data(orderService.getOrder(orderId));
    }

    @GetMapping("/")
    public JsonResult<?> addOrder(){
        Order order = new Order();
        order.setId("jijaiogndgd");
        order.setUser(new User(11,"测试用户11","jfdsjfd"));
        order.setItems(Arrays.asList(
                new Item[]{
                        new Item(1,"商品1",1),
                        new Item(12,"商品12",12),
                        new Item(13,"商品13",13),
                        new Item(14,"商品14",14),
                        new Item(15,"商品15",15)
                }
        ));
        orderService.addOrder(order);
        return JsonResult.ok().msg("添加订单成功");
    }
}
